<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
    <head>
        <title>美业红</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1">
        <link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
        <link href="/public/css/main.css" rel="stylesheet">
        <script type='text/javascript' src='/public/js/jquery-3.1.1.min.js'></script>
        <script type="text/javascript" src='/public/js/jquery.validate.js'></script>
        <script type="text/javascript" src='/public/js/main/main.js'></script>
        <script>
            var _hmt = _hmt || [];
            (function () {
                var hm = document.createElement("script");
                hm.src = "//hm.baidu.com/hm.js?8d43b5b5d798921b66d689f7a792e6e2";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
        <script type="text/javascript">
            document.domain = '<?php echo _DOMAIN_ALL_;?>';
        </script>
        <link rel="shortcut icon" type="image/ico" href="/favicon.ico">
    </head>
    <body style="background-color: #f4f4f4;">
        <div class="navigation">
            <div class='navlogo'>
            <a href='/'><img class='_navlogo' src="/public/images/logo.png"></a>
            </div>
            <div class='navson'>
                <ul class='fr'>
                <li><a href='/' class='anchor'><b>主页</b></a></li>
                <li><a href="/home/store" class='anchor'><b>店铺</b></a></li>
                <li><a href="/home/barber" class='anchor'><b>成员</b></a></li>
                <li><a href="/home/action" class='anchor'><b>活动</b></a></li>
                <li><a href="/home/order" class='anchor'><b>订单</b></a></li>
                <li><a href="/home/coupon" class='anchor'><b>优惠券</b></a></li>
                <li><a href="/home/goods" class='anchor'><b>商品</b></a></li>
                </ul>
           </div>
            <?php if($_SESSION['id']>0){?>
            <div style="float:right;padding-right:10%">你好:<span id='login_name'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/repassword'>修改密码</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class='anchor' href='/home/passport/logout'>退出</a></div>
            <?php }?>
        </div>
        <div style='margin-top:80px;width:100%'>
            <img class='_navlogo' src="/public/images/contentlogo.png" style='width:100%;height:100px'>
        </div>
        <div class='container'>
            <div class='_main'>
            <div class='_line'></div> 
<div class="_contro">
        <span style="font-size:1.8rem;padding-right:5rem;">共查询出 <span style="color:red" id='num'><?php echo $count; ?></span> 条记录</span>
        <input type="text"  placeholder="请输入识别码/手机号" value="<?php echo $search?>" id='Search' name='Search'/> 
        <input type='submit' value='查询' id='submit'/>
        <input type='hidden' id='coupon_id'  value="<?php echo $coupon_id;?>"/>          
        <select id="type" name="type">
            <option value="0" <?php if($type == 0){echo 'selected="selected"';}?> >全部</option>
            <option value="1" <?php if($type == 1){echo 'selected="selected"';}?> >已使用</option>
            <option value="2" <?php if($type == 2){echo 'selected="selected"';}?> >未使用</option>
        </select>
</div>
<div class="_cut"></div>
<div id='content'>
    <?php foreach($ling as $k=>$v){ ?>
    <?php if($k%3==0){?>
<div class='row'>
    <?php }?>
    <div class='col-sm-3 col-md-4' style="margin-bottom:10px;">
        <div class="thumbnail" style="margin-bottom:2px;">
            <div class='caption _order <?php if($v["status"]==0){echo "_ling2";}elseif($v["status"]==1){echo "_ling3";}?>'  >
                <div class='_ling_div' style='margin-left:4rem;font-size:14px;padding:11px;'>
                    <div>
                        <span>手机号：<?php echo $v['client_id']['mobile'];?></span>
                    </div>
                    <div>
                        <span>识别码：<?php echo $v['number'];?></span>
                    </div>
                    <div>
                        <span>发型师：<?php echo $v['barber_id']['name'];?></span>
                    </div> 
                    <div>
                        <span>领取时间：<?php echo date('Y-m-d H:i:s',$v['create_time']);?></span>
                    </div>
                    <?php if($v['use_time']==''){?>
                    <div>
                        <span>使用时间：未使用</span>
                    </div>
                    <?php }else{?>
                    <div>
                        <span>使用时间：<?php echo date('Y-m-d H:i:s',$v['use_time']);?></span>
                    </div>
                    <?php } ?>
                    <div style='float:right; margin-top:1rem;'>
                        <span>
                        <?php $time=time(); if($v['status']==0 && $v['end_time']>$time){ ?>
                            <a class='as' href="/home/coupon/update?id=<?php echo $v['id'];?>&coupon_id=<?php echo $v['coupon_id'];?>"onclick="return confirmAct();" ><b>验证使用</b></a>
                        <?php }elseif($v['status']==1){ ?>
                            已使用
                        <?php }else{ ?>
                            已过期
                        <?php } ?>       
                        </span>
                    </div>
                </div>
            </div>
        </div>
        
    </div>
    <?php if(($k+1)%3==0 || $ling[$k+1]['id']<1){?>
</div>
    <?php } ?>
    <?php } ?>
</div>
<input type="hidden" value="<?php echo $action_id;?>" id="action_id">
<script type='text/javascript'>
    var number = 12;
    function loaddata()
    {
        var type = $('#type').val();
        var search = $("#Search").val();
        var coupon_id = $("#coupon_id").val();
        if(number ==-1){
            return;
        }
        totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());

        if ($(document).height() <= totalheight)
        {
            $.ajax({ url: "/home/coupon/append?Search="+search+"&type="+type+"&start="+number+'&coupon_id='+coupon_id,async:true, success: function(msg){
                    if(msg == 'false'){
                        number = -1;
                        return ;
                    }
                    var html = "";
                    msg = eval('(' + msg + ')');
                    $.each(msg,function(i,v){
                        if(i%3==0){
                            html += "<div class='row'>";
                        }
                        html += "<div class='col-sm-3 col-md-4'>";
                        html += '<div class="thumbnail" style="margin-bottom:10px">';
                        html += "<div class='caption _order";
                        if(v.status==0){
                            html += " _ling2'>";
                        }else if(v.status==1){
                            html += " _ling3'>";
                        }
                        html += "<div class='_ling_div' style='margin-left:4rem;font-size:14px;padding:11px;'>";
                        html += "<div><span>手机号：";
                        html += v.client_id.mobile==null?'':v.client_id.mobile;
                        html += "</span></div>";
                        html += "<div><span>识别码：";
                        html += v.number==null?'':v.number;
                        html += "</span></div>";
                        /*html += "<div><span>发型师：";
                        html += v.barber_id.name==null?'':v.barber_id.name;
                        html += "</span></div>";*/
                        html += "<div><span>领取时间：";
                        var time1 = v.create_time;
                        var create_time = UnixToDate(time1,8);
                        var time2 = v.use_time
                        if(time2 !=null){
                            var use_time = UnixToDate(time2,8);
                        }

                        html += create_time==null?'':create_time;
                        html += "</span></div>";
                        html += "<div><span>使用时间：";
                        html += use_time==null?'未使用':use_time;
                        html += "</span></div>";
                        html += "</div><div style='padding-right:3px; height:2rem;font-size:14px;'>";
                        var str = '<a class="as" style="float:right;margin-top:1rem;" href="/home/coupon/update?id='+v.id+'&coupon_id='+v.coupon_id+'" onclick="return confirmAct();" ><b>验证使用</b></a>';
                         if(v.status==0 && v.end_time><?php echo time();?>){
                            html +=str;
                         }else if(v.status==1){
                            html += '<span style="float:right;color:white;margin-top:1rem;font-size:14px;" >已使用</span>';
                         }else{
                            html += '<span style="float:right;color:white;margin-top:1rem;font-size:14px;" >已过期</span>';
                         }
                        html += "</div></div></div></div>";
                        if((i+1)%3==0){
                            html += "</div>";
                        }
                        number += 1;
                    });
                    $('#content').append(html);
            }});
        }
    }

    $(window).scroll(function () {
        loaddata();
    });
    $(document).ready(function(){
        $("#type").change(function(){
            var type = $("#type").val();
            var Search = $("#Search").val();
            var coupon_id = $("#coupon_id").val();
            setTimeout(window.location.href='/home/coupon/search?type='+type+'&Search='+Search+'&coupon_id='+coupon_id);    
        });
        $("#submit").click(function(){
            var type = $("#type").val();
            var Search = $("#Search").val();
            var coupon_id = $("#coupon_id").val();
            setTimeout(window.location.href='/home/coupon/search?type='+type+'&Search='+Search+'&coupon_id='+coupon_id);
        });
    });


function confirmAct() 
{ 
  if(confirm('确定要执行此操作吗?')) 
  { 
    return true; 
  } 
  return false; 
} 

 function UnixToDate(unixTime,timeZone) {
        if (typeof (timeZone) == 'number')
        {
          unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
        }
        var time = new Date(unixTime * 1000);
        var ymdhis = "";
        ymdhis += time.getUTCFullYear() + "-";
        ymdhis += (time.getUTCMonth()+1) + "-";
        ymdhis += time.getUTCDate();
        ymdhis += " " + time.getUTCHours() + ":";
        ymdhis += time.getUTCMinutes() + ":";
        ymdhis += time.getUTCSeconds();

        return ymdhis;
  }
</script>
 

</div>
</div>
<div class='_line'></div>
<div class="newfooter">
    ©2015-2017 All Rights Reserved ( 京ICP备15010043号 ) 
</div>
<div id='mask_layer' style="text-align: center;width:100%;height:100%;overflow:hidden;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#8E8E8E',endColorstr='##8E8E8E');
     background-color:rgba(255, 255, 255, 0.4);position:fixed; _position:absolute; top:0;left:0; z-index:5000;display:none ">
    <div style="padding-top: 20%"><h1><b>loading<span id="_loading"></span></b></h1></div>
</div>
</body>
<script type="text/javascript" src='/public/js/top.js'></script>
</html>